


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝首页相关接口
 *
 * allen  2023-12-19
 */



/**
* 
* 收藏列表接口
* data:{
  category:'product',//article
*  page:1,
*  limit:10
* }
*/
const collectList = (data) => {
  return new Promise((resolve, reject) => {
    get("/api/front/collect/user", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 添加到收藏接口
 * data:{
 *   category:"product",
 *   id:5
 * }
 */
const addCollect = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/collect/add", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 获取订单评价
 * data:{
 *   category:"product",
 *   id:5
 * }
 */
const getOrderCommentSku = (orderId,productId,unique) => {
  return new Promise((resolve, reject) => {
    get("/api/front/order/commentSku?orderId=" + orderId + "&productId=" + productId + "&unique=" + unique).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
* 
* 取消收藏接口
* data:{
*   
*   productId:5
* }
*/
const cancelCollect = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/collect/delete",data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  * 
  * 提交评价接口
  * data:{
  *  
  * }
  */
const submitReply = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/order/comment", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  * 
  * 获取需要评价的商品信息
  * data:{
  *   uni:,
  *   orderId
  * }
  */
const queryReplyPorductInfo = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/order/product", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
  * 
  * 获取需要评价的商品信息
  * data:{
  *    params:{
  * 
  *   },
  *   page:"pages/home/home"
  * }
  */
const queryShareQrCode = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/qrcode/get/url", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  *
  * 绑定人员关系
  * 
  */
const bindSpread = (id) => {
  return new Promise((resolve, reject) => {
    get("/api/front/user/bindSpread?spreadPid=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  *
  * 绑定礼品卡验证码
  * 
  */
const getSmsCode = (phone) => {
  return new Promise((resolve, reject) => {
    get("/api/front/sms/common?phone=" + phone).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




/**
  *
  * 验证老手机号
  * data:{
  *  phone:"",
  * captcha:"",//验证码
  * }
  */
const verifyOldPhone = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/update/binding/verify", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
  *
  * 换绑新手机号
  * data:{
  *  phone:"",
  * captcha:"",//验证码
  * }
  */
const bindNewPhone = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/update/binding", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
  *
  * 消息列表
  */
const msgList = (page, limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/msg?page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  *
  * 单条消息已读
  */
const singleMsgRead = (id) => {
  return new Promise((resolve, reject) => {
    put("/api/front/msg/read/" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
  *
  * 全部消息已读
  */
const allMsgRead = () => {
  return new Promise((resolve, reject) => {
    put("/api/front/msg/read/all").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
  *未读消息数量
  * 
  */
const notReadMsgNumber = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/msg/index").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  *查询是否已有定制列表
  * 
  */
const queryMyCustomList = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/custom/list?page=" + 1 + "&limit=" + 30).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
  *创建定制需求
  * data:{
  *   type:"",问题类型，前端中文写死
  *   problem:"",//描述的问题
  *   images:["","","","","",""],//图片
  * }
  */
const createCustomNeed = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/custom", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}







module.exports = {
  addCollect,
  submitReply,
  queryReplyPorductInfo,
  cancelCollect,
  collectList,
  queryShareQrCode,
  bindSpread,
  getSmsCode,
  verifyOldPhone,
  bindNewPhone,
  msgList,//消息列表
  singleMsgRead,//单条消息已读
  allMsgRead,//全部消息已读
  notReadMsgNumber,//未读消息数量
  queryMyCustomList,
  createCustomNeed,//创建定制需求
  getOrderCommentSku,
}

